<?php
/**
 * 系统日志管理
 *
 * @copyright zhanghuan
 * @since 2012-05-16
 */

include_once($_SERVER["DOCUMENT_ROOT"] . "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/core/admin.inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/foodv2/inc.php");


function check_cgi_pro()
{		
	global $g_cgival, $g_pro, $g_show;

	cgi::both($g_cgival['p'],"p",1);
	cgi::both($g_cgival['pcount'],"pcount",20);

	cgi::both($g_cgival['starttime'],"starttime",'');
	$g_cgival['starttime'] = string::un_html($g_cgival['starttime']);
	
	cgi::both($g_cgival['endtime'],"endtime",'');
	$g_cgival['admin_username'] = string::un_html($g_cgival['admin_username']);
	
	cgi::both($g_cgival['admin_username'],"admin_username",'');
	$g_cgival['admin_username'] = string::un_html($g_cgival['admin_username']);
	
	cgi::both($g_cgival['get_admin_log_type'],"admin_log_type","");
	$g_cgival['get_admin_log_type'] = string::un_html($g_cgival['get_admin_log_type']);


}
function get_data()
{
	global $g_cgival, $g_pro, $g_show,$config;

	$site_id = admin::admin_get_user_site_id();
	$admin_id = admin::admin_get_login_uid();

	$g_show['admin_log_type'] = $config['admin_log_type'];
	$g_show['starttime'] = $g_cgival['starttime'];
	$g_show['endtime'] = $g_cgival['endtime'];
	$g_show['admin_username'] = $g_cgival['admin_username'];
	$g_show['get_admin_log_type'] = $g_cgival['get_admin_log_type'];
	
	$p = $g_cgival['p'];
	$pcount = $g_cgival['pcount'];

	$admin_log = new admin_log();
	$g_show['list'] = $admin_log->admin_get_log_list_by_key($site_id, $g_show['admin_username'], $g_show['get_admin_log_type'], $g_show['starttime'], $g_show['endtime'], $p, $pcount);
	foreach ($g_show['list'] as $key=>$val)
	{
		$g_show['list'][$key]['op_type'] = $config['admin_log_type'][$val['op_type']];
	}

	$g_show['count'] = $admin_log->admin_get_log_total_num_by_key($site_id, $g_show['admin_username'], $g_show['get_admin_log_type'], $g_show['starttime'], $g_show['endtime']);
	$max_page = page_bar::get_page_max($g_show["count"], $pcount, $p);
	$page_bar_style = array(
			"curt"		=> $p,
			"max"		=> $max_page,
			"key"		=> "p",
			);
	$g_show["page_bar"] = "<b>{$g_show["count"]}</b> 条记录&nbsp;&nbsp;第{$g_cgival["p"]}页&nbsp;共{$max_page}页&nbsp;" . page_bar::bar2($page_bar_style);	
}
try
{
	
    admin_check_login();
	check_cgi_pro();
	get_data();

	$g_show["error"] = "0";
	$g_show["errmsg"] = "";
}
catch (Exception $e)
{
	$g_show["error"] = "1";
	$g_show["errmsg"] = $e->getMessage();
}
show_pro();
exit();

function show_pro()
{
	global $g_cgival, $g_pro, $g_show;

	$smarty = p_get_smarty();
	$smarty->assign('g_show', $g_show);

	if ($g_show["error"] == "0")
	{
		$smarty->assign('g_show', $g_show);	//版块信息


		$smarty->display("foodv2/admin_log/food_admin_log.html");
	}
	else
	{
		$smarty->display("admin/admin_error.html");//指定错误页面
	}
}

?>